﻿namespace Baddies.GUI
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Baddies.Events;
    using Baddies.Nodes;
    using Baddies.Utils;   
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;     
    
    /// <summary>
    /// Box class.
    /// </summary>
    public class BoxGUI : GUINode
    {
        /// <summary>
        /// Width of th box.
        /// </summary>
        private int w;

        /// <summary>
        /// Height of the box.
        /// </summary>
        private int h;

        /// <summary>
        /// Background color of the box.
        /// </summary>
        private Color color;

        /// <summary>
        /// Quick rectangle for drawing.
        /// </summary>
        private Rectangle drawRect;

        /// <summary>
        /// Texture to draw.
        /// </summary>
        private Texture2D drawTexture;

        /// <summary>
        /// Gets or sets the width of the box.
        /// </summary>
        /// <value>The width of the box.</value>
        public int W
        {
            get { return this.w; }
            set { this.w = value; }
        }

        /// <summary>
        /// Gets or sets the height of the box.
        /// </summary>
        /// <value>The height of the box.</value>
        public int H
        {
            get { return this.h; }
            set { this.h = value; }
        }

        /// <summary>
        /// Initializes a new instance of the BoxGUI class.
        /// </summary>
        public BoxGUI()
            : base()
        {
            this.w = 0;
            this.h = 0;
            this.color = Color.Yellow;

            // Create texture.
            this.ChangeBGColor(Color.White);

            // Create rectangle
            this.drawRect = new Rectangle();
        }

        /// <summary>
        /// Changes the background color of the rectangle.
        /// </summary>
        /// <param name="newColor">New color to change to.</param>
        public void ChangeBGColor(Color newColor)
        {
            GetGameGfxDeviceArg args = new GetGameGfxDeviceArg();
            EventManager.GetEV.Trigger("GetGameGfxDevice", this, args);
            this.drawTexture = new Texture2D(args.GraphicsDevice, 1, 1);
            this.drawTexture.SetData(new[] { newColor });
        }

        /// <summary>
        /// Draws the Box.
        /// </summary>
        /// <param name="spritebatch">SpriteBatch to draw on.</param>
        public override void Draw(SpriteBatch spritebatch)
        {
            this.drawRect.X = (int)this.DrawPosition.X;
            this.drawRect.Y = (int)this.DrawPosition.Y;
            this.drawRect.Width = this.w;
            this.drawRect.Height = this.h;

            spritebatch.Draw(this.drawTexture, this.drawRect, this.color);
        }
    }
}
